/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.Random;

/**
 * <p>Project: javaseapp - Arr4
 * <p>Powered by webrx On 2021-08-04 09:49:29
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Arrays1 {
    public static void main(String[] args) {
        int[] a = {1, 2, 3, 4, 5, 60, 700};
        System.out.println(a.length);//7
        System.out.println(a);//[I@119d7047
        //数组转字符串
        System.out.println(Arrays.toString(a)); //[1, 2, 3, 4, 5, 60, 700]

        int[][][] b = {{{1, 2}, {1, 2, 3}}, {{10, 20, 30}, {55, 66}}, {{1}, {2, 3}, {4, 5050, 6}, {7, 8, 9, 10, 11}}};
        System.out.printf("%d%n", b[2][2][1]);
        System.out.println(Arrays.deepToString(b));

        //填充数组
        int[] c = new int[6];
        Arrays.fill(c, 3);
        System.out.println(Arrays.toString(c));
        Arrays.fill(c, 1, 2, 10);
        Random rand = new Random();
        Arrays.fill(c, rand.nextInt(100) + 1);
        System.out.println(Arrays.toString(c));

        Integer[] nn = new Integer[]{3, 1, 0, 10, 50, 20, 35, 99};
        System.out.println(Arrays.toString(nn));
        //Arrays.sort(nn);
        Arrays.sort(nn, (x, y) -> x - y);
        Arrays.sort(nn, (x, y) -> y - x);
        System.out.println(Arrays.toString(nn));

        String[] ss = new String[]{"an", "javascript", "egg", "book", "user", "zoo", "c", "c++"};
        System.out.println(Arrays.toString(ss));
        //Arrays.sort(ss);
        //升序，按字母顺序
        Arrays.sort(ss, (s1, s2) -> s1.compareTo(s2));
        //降序
        Arrays.sort(ss, (s1, s2) -> s2.compareTo(s1));

        Arrays.sort(ss, (s1, s2) -> s1.length() - s2.length());
        Arrays.sort(ss, (s1, s2) -> s2.length() - s1.length());
        System.out.println(Arrays.toString(ss));
    }

}
